package com.zl.open_app;

import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Stack;

import android.util.Log;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.Intent;
import android.content.Context;

public class ScreenManager {
	
     private static String TAG = "Screen";
	
	 private static Stack<Activity> activityStack;
	 private static ScreenManager instance;
	 private  ScreenManager(){
	 }
	 public static ScreenManager getScreenManager(){
	  if(instance==null){
	   instance=new ScreenManager();
	  }
	  return instance;
	 }
	//退出栈顶Activity
	 public void popActivity(Activity activity){
	  if(activity!=null){
	   activity.finish();
	   activityStack.remove(activity);
	   activity=null;
	  }
	 }
	//获得当前栈顶Activity
	 public Activity currentActivity(){
	  Activity activity=activityStack.lastElement();
	  //Log.d(TAG,"当前的界面所属activity："+ activity.toString());
	  return activity;
	 }
	//将当前Activity推入栈中
	 public void pushActivity(Activity activity){
	  if(activityStack==null){
	   activityStack=new Stack<Activity>();
	  }
	  activityStack.add(activity);
	 }
	 //退出栈中所有Activity
	 public void popAllActivityExceptOne(Class cls){
	  while(true){
	   Activity activity=currentActivity();
	   if(activity==null){
	    break;
	   }
	   if(activity.getClass().equals(cls) ){
	    break;
	   }
	   popActivity(activity);
	  }
	 }
	}
